import locationUtil from "@/utils/positionConversion";

export function getCurrentLocation() {
  return new Promise((resolve, reject) => {
    uni.getLocation({
      type: "wgs84 ",
      geocode: true,
      isHighAccuracy: true, //开启高精度定位
      success(res: UniApp.GetLocationSuccess) {
        const latitude = res.latitude;
        const longitude = res.longitude;
        const gcj02Location = locationUtil.wgs84Togcj02(longitude, latitude);
        const data = {
          wgsLocation: {
            latitude,
            longitude
          },
          gcjLocation: {
            latitude: gcj02Location[1],
            longitude: gcj02Location[0]
          }
        };
        resolve(data);
      },
      fail(err) {
        reject(err);
      }
    });
  });
}
